#include "ShipJosh.h"
#include <GL/glu.h>
#include "gllib/Objects.h"
#include <math.h>
#include "mathlib/Vector.h"

void ShipJosh::draw() {

    glEnable(GL_COLOR_MATERIAL);
    glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);

    float mat_specular[] = {0.7, 0.7, 0.7, 1.0};
    float shininess = 10;

    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialf(GL_FRONT, GL_SHININESS, shininess);

    halfShip();

    glDisable(GL_COLOR_MATERIAL);

}

void ShipJosh::halfShip(){
    float espelhamentoX[4][4] = {{-1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1}};
    Point3 vertices[58];

    vertices[0] = Point3(0.0,0.0,0.0);
    vertices[1] = Point3(0.0,0.0,-0.5);
    vertices[2] = Point3(0.0,0.0,-1.0);
    vertices[3] = Point3(0.0,0.0,-1.5);
    vertices[4] = Point3(0.0,0.0,-2.0);
    vertices[5] = Point3(0.0,0.0,-2.5);
    vertices[6] = Point3(0.0,0.0,-3.0);

    vertices[7] = Point3(0.0,0.5,0.3);
    vertices[8] = Point3(0.3,0.5,-0.5);
    vertices[9] = Point3(0.3,0.5,-1.0);
    vertices[10] = Point3(0.3,0.5,-1.5);
    vertices[11] = Point3(0.3,0.5,-2.0);
    vertices[12] = Point3(0.3,0.5,-2.5);
    vertices[13] = Point3(0.0,0.5,-3.3);

    vertices[14] = Point3(0.0,1.0,0.4);
    vertices[15] = Point3(0.4,1.0,-0.5);
    vertices[16] = Point3(0.4,1.0,-1.0);
    vertices[17] = Point3(0.4,1.0,-1.5);
    vertices[18] = Point3(0.4,1.0,-2.0);
    vertices[19] = Point3(0.4,1.0,-2.5);
    vertices[20] = Point3(0.0,1.0,-3.4);

    vertices[21] = Point3(0.0,1.3,0.4);
    vertices[22] = Point3(0.4,1.3,-0.5);
    vertices[23] = Point3(0.4,1.3,-1.0);
    vertices[24] = Point3(0.4,1.3,-1.5);
    vertices[25] = Point3(0.4,1.3,-2.0);
    vertices[26] = Point3(0.4,1.3,-2.5);
    vertices[27] = Point3(0.0,1.3,-3.4);

    vertices[28] = Point3(0.0,1.0,-0.5);
    vertices[29] = Point3(0.25,1.0,-0.5);
    vertices[30] = Point3(0.25,1.0,-2.5);
    vertices[31] = Point3(0.0,1.0,-2.5);

    vertices[32] = Point3(0.0,1.5,-0.5);
    vertices[33] = Point3(0.25,1.5,-0.5);
    vertices[34] = Point3(0.25,1.5,-2.5);
    vertices[35] = Point3(0.0,1.5,-2.5);

    vertices[36] = Point3(0.0,1.5,-1.8);
    vertices[37] = Point3(0.0618,1.5,-1.80979);
    vertices[38] = Point3(0.11756,1.5,-1.8382);
    vertices[39] = Point3(0.1618,1.5,-1.88244);
    vertices[40] = Point3(0.19021,1.5,-1.9382);
    vertices[41] = Point3(0.2,1.5,-2.0);
    vertices[42] = Point3(0.19021,1.5,-2.0618);
    vertices[43] = Point3(0.1618,1.5,-2.11756);
    vertices[44] = Point3(0.11756,1.5,-2.1618);
    vertices[45] = Point3(0.0618,1.5,-2.19021);
    vertices[46] = Point3(0.0,1.5,-2.2);

    vertices[47] = Point3(0.0,2.0,-1.8);
    vertices[48] = Point3(0.0618,2.0,-1.80979);
    vertices[49] = Point3(0.11756,2.0,-1.8382);
    vertices[50] = Point3(0.1618,2.0,-1.88244);
    vertices[51] = Point3(0.19021,2.0,-1.9382);
    vertices[52] = Point3(0.2,2.0,-2.0);
    vertices[53] = Point3(0.19021,2.0,-2.0618);
    vertices[54] = Point3(0.1618,2.0,-2.11756);
    vertices[55] = Point3(0.11756,2.0,-2.1618);
    vertices[56] = Point3(0.0618,2.0,-2.19021);
    vertices[57] = Point3(0.0,2.0,-2.2);



    glColor3f(0.25,0.25,0.25);
    glBegin(GL_TRIANGLE_STRIP);
        glVertex3f(vertices[7].x,vertices[7].y,vertices[7].z);
        glVertex3f(vertices[0].x,vertices[0].y,vertices[0].z);
        glVertex3f(vertices[8].x,vertices[8].y,vertices[8].z);
        glVertex3f(vertices[1].x,vertices[1].y,vertices[1].z);
        //
        glVertex3f(vertices[9].x,vertices[9].y,vertices[9].z);
        glVertex3f(vertices[2].x,vertices[2].y,vertices[2].z);
        //
        glVertex3f(vertices[10].x,vertices[10].y,vertices[10].z);
        glVertex3f(vertices[3].x,vertices[3].y,vertices[3].z);
        //
        glVertex3f(vertices[11].x,vertices[11].y,vertices[11].z);
        glVertex3f(vertices[4].x,vertices[4].y,vertices[4].z);
        //
        glVertex3f(vertices[12].x,vertices[12].y,vertices[12].z);
        glVertex3f(vertices[5].x,vertices[5].y,vertices[5].z);
        //
        glVertex3f(vertices[13].x,vertices[13].y,vertices[13].z);
        glVertex3f(vertices[6].x,vertices[6].y,vertices[6].z);
    glEnd();

    //Espelhamento
    glPushMatrix();
    glMultMatrixf(*espelhamentoX);
    glBegin(GL_TRIANGLE_STRIP);
        glVertex3f(vertices[0].x,vertices[0].y,vertices[0].z);
        glVertex3f(vertices[7].x,vertices[7].y,vertices[7].z);
        glVertex3f(vertices[1].x,vertices[1].y,vertices[1].z);
        glVertex3f(vertices[8].x,vertices[8].y,vertices[8].z);
        //
        glVertex3f(vertices[2].x,vertices[2].y,vertices[2].z);
        glVertex3f(vertices[9].x,vertices[9].y,vertices[9].z);
        //
        glVertex3f(vertices[3].x,vertices[3].y,vertices[3].z);
        glVertex3f(vertices[10].x,vertices[10].y,vertices[10].z);
        //
        glVertex3f(vertices[4].x,vertices[4].y,vertices[4].z);
        glVertex3f(vertices[11].x,vertices[11].y,vertices[11].z);
        //
        glVertex3f(vertices[5].x,vertices[5].y,vertices[5].z);
        glVertex3f(vertices[12].x,vertices[12].y,vertices[12].z);
        //
        glVertex3f(vertices[6].x,vertices[6].y,vertices[6].z);
        glVertex3f(vertices[13].x,vertices[13].y,vertices[13].z);
    glEnd();
    glPopMatrix();


    glBegin(GL_TRIANGLE_STRIP);
        glVertex3f(vertices[14].x,vertices[14].y,vertices[14].z);
        glVertex3f(vertices[7].x,vertices[7].y,vertices[7].z);
        glVertex3f(vertices[15].x,vertices[15].y,vertices[15].z);
        glVertex3f(vertices[8].x,vertices[8].y,vertices[8].z);
        //
        glVertex3f(vertices[16].x,vertices[16].y,vertices[16].z);
        glVertex3f(vertices[9].x,vertices[9].y,vertices[9].z);
        //
        glVertex3f(vertices[17].x,vertices[17].y,vertices[17].z);
        glVertex3f(vertices[10].x,vertices[10].y,vertices[10].z);
        //
        glVertex3f(vertices[18].x,vertices[18].y,vertices[18].z);
        glVertex3f(vertices[11].x,vertices[11].y,vertices[11].z);
        //
        glVertex3f(vertices[19].x,vertices[19].y,vertices[19].z);
        glVertex3f(vertices[12].x,vertices[12].y,vertices[12].z);
        //
        glVertex3f(vertices[20].x,vertices[20].y,vertices[20].z);
        glVertex3f(vertices[13].x,vertices[13].y,vertices[13].z);
    glEnd();

    //Espelhamento
    glPushMatrix();
    glMultMatrixf(*espelhamentoX);
    glBegin(GL_TRIANGLE_STRIP);
        glVertex3f(vertices[7].x,vertices[7].y,vertices[7].z);
        glVertex3f(vertices[14].x,vertices[14].y,vertices[14].z);
        glVertex3f(vertices[8].x,vertices[8].y,vertices[8].z);
        glVertex3f(vertices[15].x,vertices[15].y,vertices[15].z);
        //
        glVertex3f(vertices[9].x,vertices[9].y,vertices[9].z);
        glVertex3f(vertices[16].x,vertices[16].y,vertices[16].z);
        //
        glVertex3f(vertices[10].x,vertices[10].y,vertices[10].z);
        glVertex3f(vertices[17].x,vertices[17].y,vertices[17].z);
        //
        glVertex3f(vertices[11].x,vertices[11].y,vertices[11].z);
        glVertex3f(vertices[18].x,vertices[18].y,vertices[18].z);
        //
        glVertex3f(vertices[12].x,vertices[12].y,vertices[12].z);
        glVertex3f(vertices[19].x,vertices[19].y,vertices[19].z);
        //
        glVertex3f(vertices[13].x,vertices[13].y,vertices[13].z);
        glVertex3f(vertices[20].x,vertices[20].y,vertices[20].z);
    glEnd();
    glPopMatrix();

    glColor3f(1.0,0.88,0.56);
    glBegin(GL_POLYGON);
        glVertex3f(vertices[14].x,vertices[14].y,vertices[14].z);
        glVertex3f(vertices[15].x,vertices[15].y,vertices[15].z);
        glVertex3f(vertices[16].x,vertices[16].y,vertices[16].z);
        glVertex3f(vertices[17].x,vertices[17].y,vertices[17].z);
        glVertex3f(vertices[18].x,vertices[18].y,vertices[18].z);
        glVertex3f(vertices[19].x,vertices[19].y,vertices[19].z);
        glVertex3f(vertices[20].x,vertices[20].y,vertices[20].z);
        glVertex3f(vertices[14].x,vertices[14].y,vertices[14].z);
    glEnd();

    //Espelhamento
    glPushMatrix();
    glMultMatrixf(*espelhamentoX);
    glBegin(GL_POLYGON);
        glVertex3f(vertices[14].x,vertices[14].y,vertices[14].z);
        glVertex3f(vertices[20].x,vertices[20].y,vertices[20].z);
        glVertex3f(vertices[19].x,vertices[19].y,vertices[19].z);
        glVertex3f(vertices[18].x,vertices[18].y,vertices[18].z);
        glVertex3f(vertices[17].x,vertices[17].y,vertices[17].z);
        glVertex3f(vertices[16].x,vertices[16].y,vertices[16].z);
        glVertex3f(vertices[15].x,vertices[15].y,vertices[15].z);
        glVertex3f(vertices[14].x,vertices[14].y,vertices[14].z);
    glEnd();
    glPopMatrix();

    glColor3f(1.0,1.0,1.0);
    glBegin(GL_LINES);
        glVertex3f(vertices[14].x,vertices[14].y,vertices[14].z);
        glVertex3f(vertices[21].x,vertices[21].y,vertices[21].z);
        glVertex3f(vertices[15].x,vertices[15].y,vertices[15].z);
        glVertex3f(vertices[22].x,vertices[22].y,vertices[22].z);
        glVertex3f(vertices[16].x,vertices[16].y,vertices[16].z);
        glVertex3f(vertices[23].x,vertices[23].y,vertices[23].z);
        glVertex3f(vertices[17].x,vertices[17].y,vertices[17].z);
        glVertex3f(vertices[24].x,vertices[24].y,vertices[24].z);
        glVertex3f(vertices[18].x,vertices[18].y,vertices[18].z);
        glVertex3f(vertices[25].x,vertices[25].y,vertices[25].z);
        glVertex3f(vertices[19].x,vertices[19].y,vertices[19].z);
        glVertex3f(vertices[26].x,vertices[26].y,vertices[26].z);
        glVertex3f(vertices[20].x,vertices[20].y,vertices[20].z);
        glVertex3f(vertices[27].x,vertices[27].y,vertices[27].z);
    glEnd();
    glBegin(GL_LINE_STRIP);
        glVertex3f(vertices[21].x,vertices[21].y,vertices[21].z);
        glVertex3f(vertices[22].x,vertices[22].y,vertices[22].z);
        glVertex3f(vertices[23].x,vertices[23].y,vertices[23].z);
        glVertex3f(vertices[24].x,vertices[24].y,vertices[24].z);
        glVertex3f(vertices[25].x,vertices[25].y,vertices[25].z);
        glVertex3f(vertices[26].x,vertices[26].y,vertices[26].z);
        glVertex3f(vertices[27].x,vertices[27].y,vertices[27].z);
    glEnd();

    //Espelhamento
    glPushMatrix();
    glMultMatrixf(*espelhamentoX);
    glBegin(GL_LINES);
        glVertex3f(vertices[14].x,vertices[14].y,vertices[14].z);
        glVertex3f(vertices[21].x,vertices[21].y,vertices[21].z);
        glVertex3f(vertices[15].x,vertices[15].y,vertices[15].z);
        glVertex3f(vertices[22].x,vertices[22].y,vertices[22].z);
        glVertex3f(vertices[16].x,vertices[16].y,vertices[16].z);
        glVertex3f(vertices[23].x,vertices[23].y,vertices[23].z);
        glVertex3f(vertices[17].x,vertices[17].y,vertices[17].z);
        glVertex3f(vertices[24].x,vertices[24].y,vertices[24].z);
        glVertex3f(vertices[18].x,vertices[18].y,vertices[18].z);
        glVertex3f(vertices[25].x,vertices[25].y,vertices[25].z);
        glVertex3f(vertices[19].x,vertices[19].y,vertices[19].z);
        glVertex3f(vertices[26].x,vertices[26].y,vertices[26].z);
        glVertex3f(vertices[20].x,vertices[20].y,vertices[20].z);
        glVertex3f(vertices[27].x,vertices[27].y,vertices[27].z);
    glEnd();
    glBegin(GL_LINE_STRIP);
        glVertex3f(vertices[21].x,vertices[21].y,vertices[21].z);
        glVertex3f(vertices[22].x,vertices[22].y,vertices[22].z);
        glVertex3f(vertices[23].x,vertices[23].y,vertices[23].z);
        glVertex3f(vertices[24].x,vertices[24].y,vertices[24].z);
        glVertex3f(vertices[25].x,vertices[25].y,vertices[25].z);
        glVertex3f(vertices[26].x,vertices[26].y,vertices[26].z);
        glVertex3f(vertices[27].x,vertices[27].y,vertices[27].z);
    glEnd();
    glPopMatrix();

    glColor3f(1.0,1.0,1.0);
    glBegin(GL_QUAD_STRIP);
        glVertex3f(vertices[32].x,vertices[32].y,vertices[32].z);
        glVertex3f(vertices[28].x,vertices[28].y,vertices[28].z);
        glVertex3f(vertices[33].x,vertices[33].y,vertices[33].z);
        glVertex3f(vertices[29].x,vertices[29].y,vertices[29].z);
        glVertex3f(vertices[34].x,vertices[34].y,vertices[34].z);
        glVertex3f(vertices[30].x,vertices[30].y,vertices[30].z);
        glVertex3f(vertices[35].x,vertices[35].y,vertices[35].z);
        glVertex3f(vertices[31].x,vertices[31].y,vertices[31].z);
    glEnd();
    glBegin(GL_QUADS);
        glVertex3f(vertices[32].x,vertices[32].y,vertices[32].z);
        glVertex3f(vertices[33].x,vertices[33].y,vertices[33].z);
        glVertex3f(vertices[34].x,vertices[34].y,vertices[34].z);
        glVertex3f(vertices[35].x,vertices[35].y,vertices[35].z);
    glEnd();

    //Espelhamento
    glPushMatrix();
    glMultMatrixf(*espelhamentoX);
    glBegin(GL_QUAD_STRIP);
        glVertex3f(vertices[28].x,vertices[28].y,vertices[28].z);
        glVertex3f(vertices[32].x,vertices[32].y,vertices[32].z);
        glVertex3f(vertices[29].x,vertices[29].y,vertices[29].z);
        glVertex3f(vertices[33].x,vertices[33].y,vertices[33].z);
        glVertex3f(vertices[30].x,vertices[30].y,vertices[30].z);
        glVertex3f(vertices[34].x,vertices[34].y,vertices[34].z);
        glVertex3f(vertices[31].x,vertices[31].y,vertices[31].z);
        glVertex3f(vertices[35].x,vertices[35].y,vertices[35].z);
    glEnd();
    glBegin(GL_QUADS);
        glVertex3f(vertices[35].x,vertices[35].y,vertices[35].z);
        glVertex3f(vertices[34].x,vertices[34].y,vertices[34].z);
        glVertex3f(vertices[33].x,vertices[33].y,vertices[33].z);
        glVertex3f(vertices[32].x,vertices[32].y,vertices[32].z);
    glEnd();
    glPopMatrix();

    glColor3f(0.25,0.25,0.25);
    glBegin(GL_QUAD_STRIP);
        glVertex3f(vertices[47].x,vertices[47].y,vertices[47].z);
        glVertex3f(vertices[36].x,vertices[36].y,vertices[36].z);
        glVertex3f(vertices[48].x,vertices[48].y,vertices[48].z);
        glVertex3f(vertices[37].x,vertices[37].y,vertices[37].z);
        glVertex3f(vertices[49].x,vertices[49].y,vertices[49].z);
        glVertex3f(vertices[38].x,vertices[38].y,vertices[38].z);
        glVertex3f(vertices[50].x,vertices[50].y,vertices[50].z);
        glVertex3f(vertices[39].x,vertices[39].y,vertices[39].z);
        glVertex3f(vertices[51].x,vertices[51].y,vertices[51].z);
        glVertex3f(vertices[40].x,vertices[40].y,vertices[40].z);
        glVertex3f(vertices[52].x,vertices[52].y,vertices[52].z);
        glVertex3f(vertices[41].x,vertices[41].y,vertices[41].z);
        glVertex3f(vertices[53].x,vertices[53].y,vertices[53].z);
        glVertex3f(vertices[42].x,vertices[42].y,vertices[42].z);
        glVertex3f(vertices[54].x,vertices[54].y,vertices[54].z);
        glVertex3f(vertices[43].x,vertices[43].y,vertices[43].z);
        glVertex3f(vertices[55].x,vertices[55].y,vertices[55].z);
        glVertex3f(vertices[44].x,vertices[44].y,vertices[44].z);
        glVertex3f(vertices[56].x,vertices[56].y,vertices[56].z);
        glVertex3f(vertices[45].x,vertices[45].y,vertices[45].z);
        glVertex3f(vertices[57].x,vertices[57].y,vertices[57].z);
        glVertex3f(vertices[46].x,vertices[46].y,vertices[46].z);
    glEnd();
    glBegin(GL_POLYGON);
        glVertex3f(vertices[47].x,vertices[47].y,vertices[47].z);
        glVertex3f(vertices[48].x,vertices[48].y,vertices[48].z);
        glVertex3f(vertices[49].x,vertices[49].y,vertices[49].z);
        glVertex3f(vertices[50].x,vertices[50].y,vertices[50].z);
        glVertex3f(vertices[51].x,vertices[51].y,vertices[51].z);
        glVertex3f(vertices[52].x,vertices[52].y,vertices[52].z);
        glVertex3f(vertices[53].x,vertices[53].y,vertices[53].z);
        glVertex3f(vertices[54].x,vertices[54].y,vertices[54].z);
        glVertex3f(vertices[55].x,vertices[55].y,vertices[55].z);
        glVertex3f(vertices[56].x,vertices[56].y,vertices[56].z);
        glVertex3f(vertices[57].x,vertices[57].y,vertices[57].z);
        glVertex3f(vertices[47].x,vertices[47].y,vertices[47].z);
    glEnd();

    //Espelhamento
    glPushMatrix();
    glMultMatrixf(*espelhamentoX);
    glBegin(GL_QUAD_STRIP);
        glVertex3f(vertices[36].x,vertices[36].y,vertices[36].z);
        glVertex3f(vertices[47].x,vertices[47].y,vertices[47].z);
        glVertex3f(vertices[37].x,vertices[37].y,vertices[37].z);
        glVertex3f(vertices[48].x,vertices[48].y,vertices[48].z);
        glVertex3f(vertices[38].x,vertices[38].y,vertices[38].z);
        glVertex3f(vertices[49].x,vertices[49].y,vertices[49].z);
        glVertex3f(vertices[39].x,vertices[39].y,vertices[39].z);
        glVertex3f(vertices[50].x,vertices[50].y,vertices[50].z);
        glVertex3f(vertices[40].x,vertices[40].y,vertices[40].z);
        glVertex3f(vertices[51].x,vertices[51].y,vertices[51].z);
        glVertex3f(vertices[41].x,vertices[41].y,vertices[41].z);
        glVertex3f(vertices[52].x,vertices[52].y,vertices[52].z);
        glVertex3f(vertices[42].x,vertices[42].y,vertices[42].z);
        glVertex3f(vertices[53].x,vertices[53].y,vertices[53].z);
        glVertex3f(vertices[43].x,vertices[43].y,vertices[43].z);
        glVertex3f(vertices[54].x,vertices[54].y,vertices[54].z);
        glVertex3f(vertices[44].x,vertices[44].y,vertices[44].z);
        glVertex3f(vertices[55].x,vertices[55].y,vertices[55].z);
        glVertex3f(vertices[45].x,vertices[45].y,vertices[45].z);
        glVertex3f(vertices[56].x,vertices[56].y,vertices[56].z);
        glVertex3f(vertices[46].x,vertices[46].y,vertices[46].z);
        glVertex3f(vertices[57].x,vertices[57].y,vertices[57].z);
    glEnd();
    glBegin(GL_POLYGON);
        glVertex3f(vertices[47].x,vertices[47].y,vertices[47].z);
        glVertex3f(vertices[57].x,vertices[57].y,vertices[57].z);
        glVertex3f(vertices[56].x,vertices[56].y,vertices[56].z);
        glVertex3f(vertices[55].x,vertices[55].y,vertices[55].z);
        glVertex3f(vertices[54].x,vertices[54].y,vertices[54].z);
        glVertex3f(vertices[53].x,vertices[53].y,vertices[53].z);
        glVertex3f(vertices[52].x,vertices[52].y,vertices[52].z);
        glVertex3f(vertices[51].x,vertices[51].y,vertices[51].z);
        glVertex3f(vertices[50].x,vertices[50].y,vertices[50].z);
        glVertex3f(vertices[49].x,vertices[49].y,vertices[49].z);
        glVertex3f(vertices[48].x,vertices[48].y,vertices[48].z);
        glVertex3f(vertices[47].x,vertices[47].y,vertices[47].z);
    glEnd();
    glPopMatrix();
}
